fix: enhance resolution and enum handling in anyOf schemas#901
Conversation
olaservo
left a comment
There was a problem hiding this comment.
Hi @Edison-A-N thanks for your PR! There's a spicy take about supporting refs in tool schemas here: #755
So think that this would apply to elicitation schemas as well. I'll drop a comment there since I hadn't responded there yet. Please feel free to share your thoughts as well.
|
Hi @Edison-A-N! This looks like it builds upon #889 from last week, I see you are calling the |
|
@claude /review |
|
Claude finished @cliffhall's task in 2m 50s —— View job Code Review for PR #901OverviewThis PR successfully addresses issue #897 by enhancing Key Changes1. Enhanced
|
See modelcontextprotocol/inspector#901 * In tools.ts - added `jsonRefTest` to make sure refs handling still works - Added `JSONRefTestSchema` which requires two `PersonSchema` objects: `husband` and `wife`. - Updated the `ToolName` enum to include `JSON_REF_TEST`. - Updated `setupToolHandlers` to register the new tool in `ListToolsRequestSchema`. The `inputSchema` is generated using `zodToJsonSchema` with the `definitions` option, ensuring that the resulting JSON schema uses `$ref` for the `Person` objects. - Added a handler for the `jsonRefTest` tool in `CallToolRequestSchema` that parses the arguments and returns a success message identifying the husband and wife. - Added a new tool `userFilterTest` to `handlers/tools.ts` along with its Zod input schema designed to yield a specific JSON schema with `$ref`, `$defs`, and nullable types. - Defined `UserRoleSchema` as a Zod enum. - Defined `UserFilterSchema` with `role` (referencing `UserRoleSchema`) and `is_active` (boolean), both nullable. - Added `USER_FILTER_TEST` to `ToolName` enum. - Registered the `userFilterTest` tool in `setupToolHandlers` using `zodToJsonSchema` with `definitions` and `definitionPath: "$defs"` to match the requested output format. - Added a basic handler for `userFilterTest` in `CallToolRequestSchema`.
cliffhall
left a comment
There was a problem hiding this comment.
LGTM! 👍
Tested by adding two new tools to the mcp-maintainer-toolkit.
- USER_FILTER_TEST - Uses the exact schema proposed in the issue that this PR fixes for enums with $refs that can be null.
- JSON_REF_TEST - Tests $ref resolution to make sure it they still resolve properly.
USER_FILTER_TEST
JSON_REF_TEST
Summary
Fix
$refresolution and enum handling inanyOfschemas. Resolves issue #897 where enum types defined via$refinanyOfwere not properly resolved.Motivation and Context
Addresses issue #897:
anyOf=[$ref, null]patterns were not resolved, causing enum properties to be lost and preventing dropdown rendering.How Has This Been Tested?
anyOf=[{$ref: "#/$defs/UserRole"}, {type: "null"}]Breaking Changes
None. Bug fix maintaining backward compatibility.
Types of changes
Checklist
Additional context
resolveRef: Added circular reference detection, recursively resolves$refinanyOfnormalizeUnionType: Unified handling foranyOf=[type, null], preserves enum propertiesresolveRefbefore normalization to ensure complete schema infoFixes #897